package cn.wdm.ymcc.controller;

import cn.wdm.ymcc.CourseDoc;
import cn.wdm.ymcc.dto.SearchCourseDto;
import cn.wdm.ymcc.result.JSONResult;
import cn.wdm.ymcc.result.PageList;
import cn.wdm.ymcc.service.IEscourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class EsCourseController {
    @Autowired
    private IEscourseService iEscourseService;

    /**
     * 保存课程到Es，上架发布
     * @param doc
     * @return
     */
    @PostMapping("/savaCourse2Es")
    public JSONResult savaCourse2Es(@RequestBody CourseDoc doc){
        iEscourseService.savaCourse2Es(doc);
        return JSONResult.success();
    }

    /**
     * 删除Es中的课程，课程下架
     * @param courseId
     * @return
     */
    @DeleteMapping("/deleteCourseInEs/{courseId}")
    public JSONResult deleteCourseInEs(@PathVariable("courseId") Long courseId){
        iEscourseService.deleteCourseInEs(courseId);
        return JSONResult.success();
    }
    @PostMapping("/course/search")
    public PageList<CourseDoc> search(@RequestBody SearchCourseDto dto){
        PageList<CourseDoc> pageList=iEscourseService.searchCourseDoc(dto);
        return pageList;
    }


}
